var _uploadingFileNameToDir={};
function _header_click_jump_hook(courseId,type,recruitId,name) {
    console.log(arguments);

    window.open(basePath+"/course/thirdStep/data/management?"
        + "courseId="+courseId
        + (recruitId?"&recruitId="+recruitId:"")
        +(_listen?"&_listen":"")
        +(_debug?"&_debug":"")
    ,"_self");
}

function convertToDataType(tp) {
    switch (tp){
        case 'doc':return 1;
        case 'image':return 2;
        case 'video':return 3;
    }
    return 1;
}
var _hook_after_upload = function(vidId){
    if(_debug){
        window.open("http://base1.zhihuishu.com/able-commons/resources/cdn/ableplayer/2.0/demo.html?id="+vidId);
    }
}

function setVideoUploadCallback(param) {
    param.callbacks ={
        onFileDialogStart : function(tid) {

        },
        onError : function(id, fileName, reason) {

        },
        // 上传函数
        onUpload : function(id, fileName) {
            console.log(arguments);
            _uploadingFileNameToDir[fileName] = _dirManager.currentDirId();
        },
        // 回调函数
        onComplete : function (id, fileName, responseJSON) {
            console.log(arguments);
            if (responseJSON != '') {
                var fileData = responseJSON.data;

                // console.log(fileData);

                var p = {};
                p.name=fileData.fileName;
                p.folderId= _uploadingFileNameToDir[fileName];
                p.suffix=_fileManager.getSuffix(fileData);
                p.url=fileData.filePath;
                p.size=fileData.size;
                p.dataType=convertToDataType(fileData.comeFromType);// 资料类型(1文档2图片3视频)
                p.interfaceDataId=fileData.fileId;//
                p.privilege=_dirManager.currentDirPri();

                console.log(p);

                $.ajax({
                    url: basePath + "/course/thirdStep/file/create",
                    data: p,
                    async: true,
                    type:"POST",
                    success: function (json) {
                        if (isRequestSuccess(json)) {

                            var fileName = json.result.name;
                            var orgFileName = fileData.fileName;
                            var createDirId =  _uploadingFileNameToDir[orgFileName];

                            //如果仍在该文件夹 直接附加到尾部
                            if(createDirId == _dirManager.currentDirId()){
                                var $li = _painter.createChildrenFileOne(json.result);
                                _pageHandler.processNewItem($li);
                            }

                            _dataManager.processNewFile(json.result);

                            //当为视频时
                            if(p.dataType==3){
                                _hook_after_upload(p.interfaceDataId);

                                _opener_refresh_list();
                            }
                        }

                    }
                });
            }
        }
    }

}

function getVideoUploadParam() {
    return {
        appName : appName,// 对应应用名称
        modelName : "CourseData",// 可不写，按文件类型命名，视频为video、图片为image、其他文件为file
        userId : currentUserId, // 填写用户ID
        userName : "test",
        fileType : "video", // 上传文件类型三类： image; video; file;
        smallImgSize : "100:100", //图片或者视频的三种裁图大小
        bigImgSize : "115:141",
        middleImgSize : "260:250",
        autoConvert : "true", // true为自动转换，false或者不配置为不自动转换(上传里需要自带文档转换,Flex上传不需要自带转换.)
        vIsUploadLetv : "true", // 是否将视频上传到乐视
        // targetId : "fine-uploader", // 为按钮目标标签ID
        showProgress : "true", // 是否显示任务栏进度条
        multipleUpload : "true",
        buttonWidth : "86",
        buttonHeight : "73",// IE789下设置此按钮高度生效
        buttonText : "",
        z_language : z_locale,//上传进度国际化 1.中文 2.英文
        buttonClass : "",
        allowSuffix : "",// 限制文件上传类型
        videoConvert : "true",
        host : "http://base1.zhihuishu.com/able-commons/",
    }
}